home *** CD-ROM | disk | FTP | other *** search
-
-
- ‹
-
- ‹
-
- åHow Does Menu Events Work?
-
-
-
- When you send a Query Menu List or Query Menu event, the ideal
-
- application will dispatch the resulting high-level event as an Apple event
-
- without looking at it. The event handler provided by Menu Events forms a
-
- reply to the query on the basis of the application’s menu list structure. In
-
- the case of a Query Menu event, if the given menu ID is not valid, it
-
- returns noSuchMenuErr. Through all of this, the application stays in the
-
- background or in the foreground, wherever it was before.
-
-
-
- When you send a Select Menu Item event, the same things happen, but the
-
- event handling is more complex.
-
-
- First, it verifies that the given menu item is valid and enabled. If not, it
-
- returns noSuchMenuErr, noSuchMenuItemErr, or menuItemDisabledErr. If
-
- the menu has a non-standard menu definition procedure, its way of
-
- counting or disabling items may differ from the norm. Menu Events
-
- assumes that the count and enable/disable flags are set in the normal
-
- fashion.
-
-
- Second, it asks for the application to be brought to the front for user
-
- interaction, because it could be dangerous to feed the target application a
-
- menu selection while it is in the background, something which never
-
- happens in normal operation. If it is refused, it returns
-
- errAENoUserInteraction.
-
-
- Third, it patches some traps so that it can gain control of menu selection.
-
- If it finds that the patches are already in place, meaning that an earlier
-
- Menu event is still pending, it returns menuEventPendingErr.
-
-
- Fourth, if everything is OK, it posts an event to simulate a mouse click in
-
- the menu bar, with modifier keys if specified. The application habitually
-
- asks which menu item was selected, and the patched traps provide the
-
- given item in response. The patches then remove themselves. From
-
- there, it is exactly as though the user had actually made the selection.
-
-
- NOTE: When replying to any of the three event types, Menu Events
-
- includes a null “tattoo” parameter to prove that it handled the event,
-
- rather than some handler supplied by the application. Many Microsoft
-
- applications, for example, bind their own handler over all Apple event
-
- classes, preventing Menu Events from working. (The handler wouldn’t be
-
- a problem if it returned errAEEventNotHandled when faced with an
-
- unknown Apple event, as it should.)
-
-
-
-
- xUser Interaction Policy
-
-
- The Apple Event Manager implements a complicated but sensible model for
-
- joint sender/receiver control over user interaction. Menu Events doesn’t
-
- know which menu selections will really require user interaction, but even
-
- if it did, it would still have to request user interaction just to bring the
-
- target application to the front, where an application always expects to be
-
- when it sees a mouse-down event.
-
-
-
- The sending program must set the kAECanInteract or kAEAlwaysInteract
-
- flag in the sendMode parameter to AESend, in order to achieve user
-
- interaction. It should also set the kAECanSwitchLayer flag, allowing the
-
- target application to come to the front without having to post a
-
- notification request. If the target application is in the background, and
-
- receives a Menu event with this flag not set, it may go into a notification
-
- wait state, disrupting its usual background event processing behavior.
-
-
- If both the sending program and target application are in the background,
-
- the kAECanSwitchLayer flag has no effect, and the notification request is
-
- posted anyway. Since your sending program is indirectly instigating a
-
- user interaction, it should call AEInteractWithUser before sending the
-
- Menu event, if there is any chance that it will be in the background at the
-
- time. Another approach would be to call SetFrontProcess to activate the
-
- target application before sending it a Menu event.
-
-
- If the target application is in that rare user interaction state,
-
- kAEInteractWithSelf, where it disallows interaction requested by any
-
- other process, the Menu event handler will respect that state, and refuse
-
- the event.
-
-
- If the sending and receiving applications are on different machines, the
-
- usual program linking checks apply, namely, Sharing Setup (on/off),
-
- Users & Groups (permission to user), and Finder’s Sharing (permission to
-
- application).
-
-
- If the Menu Events extension is locked, using Finder’s Get Info dialog, then
-
- only target applications which explicitly allow interaction with all
-
- processes can be controlled by remote senders. If it is not locked, and if
-
- it sees that the user interaction state is kAEInteractWithLocal, which is
-
- the default value, it will momentarily change it to kAEInteractWithAll, so
-
- that events sent from a remote machine are not rejected. This trick is
-
- necessary for Menu Events to be useful with most target applications,
-
- because most will assume the default interaction state, not expecting any
-
- remote sender to require user interaction. The icon displayed by Menu
-
- Events at startup shows whether or not the lock is in effect.
-
-
- IMPORTANT NOTE: Users of machines where Menu Events is installed
-
- should be careful about which users and applications are enabled for
-
- remote program linking. In particular, guest users should not be allowed
-
- to do program linking unless Menu Events is locked.
-
-
-
-
- xSelf-Sending Behavior
-
-
- When you are using a high-level-event-aware application on a machine
-
- where Menu Events is installed, menu item selection behavior is modified
-
- if the Caps Lock key is down at the time you release the mouse button.
-
- Menu Events will try to nullify the menu selection and replace it with a
-
- self-addressed Select Menu Item event (including parameters for any
-
- modifier keys which were pressed), so that a script editor can record the
-
- event as a script command. A gentle “twang” sound confirms that this
-
- has happened. If it fails to send this event, the menu selection will be
-
- processed in the usual way.
-
-
-
- If the application is scriptable in its own right, a script editor may record
-
- two commands when you select an item from its menus. To prevent this
-
- duplication, you can use the item’s Command-key equivalent (if any), or
-
- release the Caps Lock key, to suppress the self-sending behavior.
-
-
- If an application seems to be misinterpreting or not receiving menu
-
- selections, try again with the Caps Lock key up. The command will not be
-
- recorded, but should work as usual.
-
-
- NOTE: While receiving a Select Menu Item event does simulate a menu
-
- selection, it does not cause a Select Menu Item script command to be
-
- recorded.
-
-
-
-